﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.Common;
using TRPOP.CRM.Component.Business;
using TRPOP.CRM.Component.Common;
using TRPOP.CRM.Component.Model;

namespace TRPOP.CRM.Web
{
    public partial class MyRemind_list : BaseAdmin
    {
        protected string m_Name = "我的工作计划";

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBase();
                BindData();
            }
        }

        /// <summary>
        /// 分页触发此事件（分页采用post方法传递数据）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void UC_PagerChanged(object sender, EventArgs e)
        {
            BindData();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strCondation = string.Empty;

            if (!txtName.Text.IsEmpty() && txtName.Text != "输入关键字")
            {
                strCondation = string.Format(" AND ( nvcCompanyName LIKE '%{0}%'  OR nvcContactName LIKE '%{0}%' )  ", txtName.Text.Trim().HtmlEncode().SQLFilter());
            }

            ViewState["SearchCondation"] = strCondation;

            BindData();
        }

        /// <summary>
        /// 批量添加工作计划
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {

        }
        #endregion

        #region 页面方法
        void LoadBase()
        {
            int intCategoryID = RequestHelper.RequestInt("id");
            
            if (intCategoryID > 0)
            {
                RemindCategoryInfo oRemindCategoryInfo = BaseManage.GetRemindCategoryInfoById(intCategoryID);
                if (oRemindCategoryInfo != null)
                {
                    ViewState["RemindCategoryInfo"] = oRemindCategoryInfo;
                    m_Name = oRemindCategoryInfo.nvcRemindCategoryName;
                }
            }
        }
        /// <summary>
        /// 绑定管理员信息列表
        /// </summary>
        protected void BindData()
        {
            int RecordCount = 0;

            string strCondition = string.Empty;
            if (ViewState["SearchCondation"] != null)
            {
                strCondition = ViewState["SearchCondation"].ToString();
            }

            if (ViewState["RemindCategoryInfo"] != null)
            {
                strCondition += " AND [iRemindCategoryID]= " + (ViewState["RemindCategoryInfo"] as RemindCategoryInfo).iRemindCategoryID;
            }

            strCondition += " AND ( [bIsEnable] =1 )  ";

            strCondition += " AND iEmployeeFollowup= " + base.GetCurrentEmployeeInfo().iEmployeeID;

            rptList.DataSource = CompanyManage.GetRemindCompanyListByPager(Pager.CurrentPage, Pager.PageSize, strCondition, string.Empty, out RecordCount);

            rptList.DataBind();

            Pager.RecordCount = RecordCount;
        }
        #endregion
    }
}